package LeetCode;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}20:48
 */
public class interview58II {
    public static void main(String[] args) {
        int[][] arr = new interview58II().findContinuousSequence(9);
        for (int i = 0; i < arr.length; i++){
            for (int j = 0;j<arr[i].length;j++){
                System.out.print(arr[i][j]);
            }
            System.out.println();
        }
    }

    public int[][] findContinuousSequence(int target){
        int i = 1;//左指针
        int j = 1;//右指针
        int sum = 0;
        List<int[]> list = new ArrayList<>();
        while (i <= target/2){
            if (sum < target){
                sum += j;
                j++;
            }else if (sum > target){
                sum -= i;//剔除i
                i++;
            }else {//相等的情况，此时就进行存取
                int[] arr = new int[j-i];
                for (int k = i; k < j;k++){
                    arr[k-i] = k;
                }
                list.add(arr);
                sum -= i;
                i++;
            }
        }
        int[][] result = new int[list.size()][];
        for (int x = 0; x < list.size();x++) {
            result[x] = list.get(x);
        }
        return result;
    }
}
